package com.cjm.algorithm.queue;

import java.util.*;

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack obj = new MinStack();
 * obj.push(val);
 * obj.pop();
 * int param_3 = obj.top();
 * int param_4 = obj.getMin();
 */
class MinStack155 {
    Deque<Integer> data = new ArrayDeque<>(Integer.MAX_VALUE);
    Deque<Integer> help = new ArrayDeque<>(Integer.MAX_VALUE);

    public MinStack155() {
    }

    public void push(int val) {
        data.add(val);
        if (help.isEmpty() || help.peekLast() >= val) {
            help.addLast(val);
        } else {
            help.addLast(help.peekLast());
        }
    }

    public void pop() {
        data.pollLast();
        help.pollLast();
    }

    public int top() {
        return data.peekLast();
    }

    public int getMin() {
        return help.peekLast();
    }
}